package com.nashuju.web.controller.sw;

import java.util.List;

import org.durcframework.core.DefaultGridResult;
import org.durcframework.core.GridResult;
import org.durcframework.core.MessageResult;
import org.durcframework.core.controller.CrudController;
import org.durcframework.core.expression.ExpressionQuery;

import com.nashuju.web.entity.sw.RUser;
import com.nashuju.web.entity.sw.RUserSch;
import com.nashuju.web.entity.sw.SReceipt;
import com.nashuju.web.entity.sw.SReimburse;
import com.nashuju.web.entity.sw.SReimburseSch;
import com.nashuju.web.service.sw.RUserService;
import com.nashuju.web.service.sw.SReimburseService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SReimburseController extends
		CrudController<SReimburse, SReimburseService> {
	@Autowired
	RUserService rUserService;
		//新增记录
	@RequestMapping("/addSReimburse.do")
	public @ResponseBody
	MessageResult addSReimburse(SReimburse entity) {
		return this.save(entity);
	}

	//删除记录
	@RequestMapping("/delSReimburse.do")
	public @ResponseBody
	MessageResult delSReimburse(SReimburse entity) {
		return this.delete(entity);
	}
	
	//修改记录
	@RequestMapping("/updateSReimburse.do")
	public @ResponseBody
	MessageResult updateSReimburse(SReimburse entity) {
		return this.update(entity);
	}

	//条件查询分页操作
	@RequestMapping("/listSReimburse.do")
	public @ResponseBody
	GridResult listSReimburse(SReimburseSch searchEntitySch) {DefaultGridResult result = (DefaultGridResult)this.query(searchEntitySch);
		List<SReimburse> receipts = (List<SReimburse> )result.getRows();
		for (SReimburse reqReceipt : receipts) {
			RUserSch userSch = new RUserSch();
			userSch.setIdSch(reqReceipt.getApplyId());
			List<RUser> users = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(userSch));	
			reqReceipt.setExcutor(users.get(0));	
		}
		return result;
		
	}

	
	//条件查询并返回所有记录
	@RequestMapping("/listAllSReimburse.do")
    public @ResponseBody Object listAllSReimburse(SReimburseSch searchEntitySch) {
        return this.queryAll(searchEntitySch);
    }

    //获取详细信息
	@RequestMapping("/getSReimburseById.do")
    public @ResponseBody SReimburse getSReimburseById(SReimburse entity) {
        return this.getService().get(entity.getId());
    }

 	

}